package com.ocom.srvpaccess.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.card.EntityCardInfo;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.srvpaccess.dao.IDaoCardInfo;
import com.ocom.srvpaccess.service.XfCardInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Locale;


@Service
public class XfCardInfoServiceImpl extends ServiceImpl<IDaoCardInfo, EntityCardInfo> implements XfCardInfoService {

    @Autowired
    private IDaoCardInfo iDaoCardInfo;

    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "companyId",isMaster = MasterSlaveEnum.MASTER)
    @Override
    public EntityCardInfo selectAccountNos(Long companyId, String cardNum) {
        QueryWrapper<EntityCardInfo> query = Wrappers.query();
//        query.select("account_no");
        query.eq("com_id",companyId);
        query.and(wrapper -> wrapper.eq("card_no", cardNum.toUpperCase(Locale.ROOT)).or().eq("card_no", cardNum.toLowerCase(Locale.ROOT)));
//        query.eq("card_no",cardNum);
        query.eq("card_state",1);
        query.orderByDesc("update_time");
        query.last("limit 1");
        return iDaoCardInfo.selectOne(query);
    }
}
